home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Util / L / Locare 1.9 SW.cpt / Locare 1.9 SW / PNTG Hook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-07-26  |  3.3 KB  |  146 lines  |  [TEXT/KAHL]

  1. /*    Locare preview hook to read MacPaint (and FullPaint) files.
  2.  
  3.     It reads up to the max size of 285 lines of a MacPaint file and then
  4.     displays these lines.
  5.  
  6.     This hook does NOT illustrate good programming techniques.  Defenses
  7.     are practically non-existent.  Feel free to use this as an example or
  8.     as a foundation for your own hooks.  If you wish to improve upon
  9.     this hook, please do not hesitate.
  10.     
  11.     Written in LightspeedC.
  12. */
  13.  
  14.  
  15.  
  16. #include <QuickDraw.h>
  17. #include <EventMgr.h>
  18. #include <MacTypes.h>
  19. #include <FileMgr.h>
  20. #include <FontMgr.h>
  21. #include <WindowMgr.h>
  22.  
  23.  
  24. #define maxsize 20520
  25.  
  26. typedef struct
  27. {    char        version;    /* 1 for now */
  28.     char        message;
  29.     int            volume;
  30.     long        directory;
  31.     int            index;
  32. }    PreviewRec;
  33.  
  34.  
  35. pascal void main(infoPtr)
  36. PreviewRec *infoPtr;
  37. {    char nameString[256];
  38.     ParamBlockRec myHRec;
  39.     int refNum,scanline;
  40.     WindowPtr myWin;
  41.     Rect rect,scrRect;
  42.     Ptr Buffer,dstPtr,saveDstPtr,saveBuffer;
  43.     BitMap theBitMap;
  44.     long size;
  45.     
  46.     myHRec.fileParam.ioFDirIndex = infoPtr->index;
  47.     myHRec.fileParam.ioFlNum = infoPtr->directory;
  48.     myHRec.fileParam.ioVRefNum = infoPtr->volume;
  49.     myHRec.fileParam.ioNamePtr = (StringPtr)nameString;
  50.     PBGetCatInfo(&myHRec,FALSE);
  51.  
  52.     myHRec.fileParam.ioFlNum = infoPtr->directory;
  53.     myHRec.fileParam.ioVRefNum = infoPtr->volume;
  54.     myHRec.fileParam.ioNamePtr = (StringPtr)nameString;
  55.     myHRec.fileParam.filler1 = fsRdPerm;    /* LS C's file mgr header
  56.             doesn't offer much support for H Rec's....ioParam offers none.
  57.             I have modified my own header to include H rec's, but maybe
  58.             you haven't.  So I just used the available fileParam, where
  59.             filler1 = ioPermssn byte. */
  60.     myHRec.fileParam.ioFDirIndex = 0;
  61.     PBHOpen(&myHRec,FALSE);
  62.     refNum = myHRec.fileParam.ioFRefNum;
  63.     rect.top = 41;
  64.     rect.left = 11;
  65.     rect.right = rect.left + 490;
  66.     rect.bottom = rect.top + 300;
  67.     
  68.     myWin = NewWindow(0L,&rect,nameString,TRUE,noGrowDocProc,-1L,FALSE,0L);
  69.     SetPort(myWin);
  70.     TextFont(monaco);
  71.     TextSize(9);
  72.     
  73.     myHRec.ioParam.ioRefNum = refNum;
  74.     PBGetEOF(&myHRec,FALSE);
  75.     size = (long)myHRec.ioParam.ioMisc - 512;    /* sub 512 byte header */
  76.     if(size > maxsize)
  77.         size = maxsize;
  78.  
  79.  
  80.     Buffer = NewPtr(maxsize);
  81.     if(Buffer == 0l)
  82.     {    DisposeWindow(myWin);
  83.         
  84.         PBClose(&myHRec,FALSE);
  85.         infoPtr->message = 1;
  86.         return;
  87.     }
  88.     saveBuffer = Buffer;
  89.     
  90.     myHRec.ioParam.ioPosMode = fsFromStart;
  91.     myHRec.ioParam.ioBuffer = Buffer;
  92.     myHRec.ioParam.ioPosOffset = 512;
  93.     myHRec.ioParam.ioReqCount = size;
  94.     PBRead(&myHRec,FALSE);
  95.     
  96.     dstPtr = NewPtr(maxsize);
  97.     if(dstPtr == 0l)
  98.     {    DisposeWindow(myWin);
  99.         DisposPtr(Buffer);
  100.         
  101.         PBClose(&myHRec,FALSE);
  102.         infoPtr->message = 1;
  103.         return;
  104.     }    
  105.     saveDstPtr = dstPtr;
  106.     
  107.     for(scanline = 0;scanline < 285; scanline++)
  108.     {    UnpackBits(&Buffer,&dstPtr,72);
  109.     }
  110.  
  111.     DisposPtr(saveBuffer);
  112.     
  113.     theBitMap.baseAddr = saveDstPtr;
  114.     theBitMap.rowBytes = 72;
  115.     theBitMap.bounds.top = 0;
  116.     theBitMap.bounds.left = 0;
  117.     theBitMap.bounds.right = 72*8;
  118.     theBitMap.bounds.bottom = 285;
  119.     
  120.     rect.top = 0;
  121.     rect.left = 0;
  122.     rect.right = rect.left + 488;
  123.     rect.bottom = rect.top + 285;
  124.  
  125.     CopyBits(&theBitMap,&myWin->portBits,&rect,&rect,srcCopy,0l);
  126.  
  127.     DisposPtr(saveDstPtr);
  128.  
  129.  
  130.     MoveTo(0,285);
  131.     LineTo(490,285);
  132.     
  133.     MoveTo(5,297);
  134.     DrawString("\p'PNTG' file preview hook by Raymond Lau.  \
  135. Please <CLICK> to continue…");
  136.     do
  137.     {}
  138.     while(!Button());
  139.     FlushEvents(mDownMask,0l);
  140.  
  141.     DisposeWindow(myWin);
  142.     
  143.     PBClose(&myHRec,FALSE);
  144.     infoPtr->message = 1;
  145.     return;
  146. }